@file:Suppress("DEPRECATION")

package com.bw.kotlinim.base

import android.app.ProgressDialog
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity

/**
 * 作用，封装公共的功能和方法，减少代码量，利于项目的扩展
 */
abstract class BaseActivity : AppCompatActivity() {
    private val inputMethodManager by lazy { getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager }

    //隐藏软键盘
    fun hideSoftKeyboard(){inputMethodManager.hideSoftInputFromWindow(currentFocus?.windowToken,0)}

    fun showSoftKeyboard(view:EditText){
        view.isFocusableInTouchMode = true
        view.isFocusable = true
        view.requestFocus()
        inputMethodManager.showSoftInput(view,0)
    }

    private val progressDialog by lazy {
        ProgressDialog(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayoutId())
        init()
    }

    open fun init() {
        //初始化一些公关功能，比如摇一摇，侧边滑动返回,子类可以腹泻,完成自己的初始化工作
    }

    //子类必须实现该方法，返回布局资源的id
    abstract fun getLayoutId(): Int


    fun showProgress(message: String) {
        progressDialog.setMessage(message)
        progressDialog.show()
    }

    fun dismissProgress() {
        progressDialog.dismiss()
    }
}